﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArxivatDeDocuments.Formularis
{
    public partial class frmRecorrerDirectoris : Form
    {

        public enum EstatRecorregut
        { 
            Recorrent,
            Cancelat,
            Acabat
        }

        public int ValorMaximBarraProgres
        {
            get { return this.ProgressBar.Maximum; }
            set { this.ProgressBar.Maximum = value; }
        }

        delegate void AvancaBarraProgresDelegate();
        public void AvancaBarraProgres()
        {
            if (this.ProgressBar.InvokeRequired)
            {
                AvancaBarraProgresDelegate d = new AvancaBarraProgresDelegate(AvancaBarraProgres);
                this.Invoke(d, new object[] {  });
            }
            else
            {
                this.ProgressBar.PerformStep();
            }           
        }

        delegate void setInfoAccioActualDelegate(string info);
        public void setInfoAccioActual(string info)
        {
            if (this.txtDirectoriActual.InvokeRequired)
            {
                setInfoAccioActualDelegate d = new setInfoAccioActualDelegate(setInfoAccioActual);
                this.Invoke(d, new object[] { info });
            }
            else
            {
                this.txtDirectoriActual.Text = info;
            }
        }

        private EstatRecorregut _Estat = EstatRecorregut.Recorrent;
        public EstatRecorregut Estat 
        {
            get { return _Estat; }
            set
            {
                _Estat = value;
                ActualitzaEstatBotons();
            }
        }

        delegate void ActualitzaEstatBotonsDelegate();
        public void ActualitzaEstatBotons()
        {
            if (this.cmdCancelar.InvokeRequired)
            {
                ActualitzaEstatBotonsDelegate d = new ActualitzaEstatBotonsDelegate(ActualitzaEstatBotons);
                this.Invoke(d, new object[] {  });
            }
            else
            {
                switch (Estat)
                {
                    case EstatRecorregut.Acabat:
                        this.cmdCancelar.Visible = false;
                        this.Close();
                        break;

                    case EstatRecorregut.Cancelat:
                        this.cmdCancelar.Enabled = false;                        
                        break;

                    case EstatRecorregut.Recorrent:
                        this.cmdCancelar.Text = "Cancelar";
                        this.cmdCancelar.Visible = true;
                        break;
                }

            }
        }

        public bool CancelPressed { get; set; }

        public frmRecorrerDirectoris()
        {
            InitializeComponent();
            ProgressBar.Step = 1;
            CancelPressed = false;
        }

        private void cmdCancelar_Click(object sender, EventArgs e)
        {
            CancelPressed = true;
            Estat = EstatRecorregut.Cancelat;
        }

    }
}
